package com.houmeiyuan.huiguniang.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author wzn
 * @date 2019-07-17 19.20
 *
 * AOP 面向切面编程
 */

@Aspect/*注入Aspect切面*/
@Component/*组件表识别*/
public class LoggerAdvice {
    private Logger logger = LoggerFactory.getLogger("access");/*info*/

    @Pointcut("execution(* com.houmeiyuan.huiguniang.service..*(..))")/*切面注入表达式*/
    private  void logger(){}

    @Before("logger()")/*前置通知，Joinpoint连接点*/
    public void doBefore(JoinPoint jp){
        logger.info("aop:before");
    }

    @Around("logger()")/*环绕通知，ProceedingIoinPoint执行目标方法*/
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
        logger.info("aop:around");
        Object object  = pjp.proceed();
        return object;
    }
}
